image: node:latest

stages:
  - build
  - test
  - deploy

cache:
  paths:
    - node_modules/

install_dependencies:
  stage: build
  script:
    - npm install -g gulp nyc parcel-bundler@^1.12.4
    - npm install
  artifacts:
    paths:
      - node_modules/

testing:
  stage: test
  script:
    - npx nyc gulp test
    - npx nyc report --reporter=html
    - npx rimraf public && npx parcel build ./src/index.pug --no-content-hash --no-minify -d ./public --public-url ./ --no-cache && node parcel-postbuild.js
  artifacts:
    paths:
      - public
      - coverage
      - .nyc_output

merge_test:
  stage: test
  script:
    - npx nyc gulp test
    - npx nyc report --reporter=html
    - npx rimraf public && npx parcel build ./src/index.pug --no-content-hash --no-minify -d ./public --public-url ./ --no-cache && node parcel-postbuild.js
  artifacts:
  only:
    - merge_requests

pages:
  stage: deploy
  script:
    - mkdir .public
    - cp -r * .public
    - mv .public public
    - mv coverage/ public/coverage/
  artifacts:
    paths:
      - public
  only:
    - master
